/**
 * Created by DukeCrushIt on 2015/7/14.
 */
//module game{
    class AssetsPool {
        private pools:Object;
        public static UiAsset:number = 0;
        public static BitMap:number = 1;

        public constructor(){
            //super();
            this.init();
        }
        private init(){
            this.pools = {};
            this.pools[0] = [];
            this.pools[1] = [];
        }

        public produce(type:number):any{
            if(type == AssetsPool.BitMap){
                var arr:egret.Bitmap[] = this.pools[1];
                if( arr.length > 0){
                    var res:egret.Bitmap = arr.pop();
                    res.alpha = 1.0;
                    res.scaleX = res.scaleY = 1.0;
                    return res;
                }
                return new egret.Bitmap();
            }else if( type == AssetsPool.UiAsset){
                var arr0:eui.Image[] = this.pools[0];
                if( arr0.length > 0){
                    var res0:egret.Bitmap = arr.pop();
                    res0.alpha = 1.0;
                    res0.scaleX = res0.scaleY = 1.0;
                    return res0;
                }
                return new eui.Image();
            }
        }

        public reclaim(obj:any, type:number){
            if(type == AssetsPool.BitMap){
                var arr:egret.Bitmap[] = this.pools[1];
                if( arr.indexOf(obj) != -1){
                   arr.push(obj);
                }
            }else if( type == AssetsPool.UiAsset){
                var arr0:eui.Image[] = this.pools[0];
                if( arr0.indexOf(obj) != -1){
                    arr0.push(obj);
                }
            }
        }

        private static _instance:AssetsPool;
        public static getInstance():AssetsPool{
            if( AssetsPool._instance == null)
                AssetsPool._instance = new AssetsPool();
            return AssetsPool._instance;
        }
    }
//}